/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * gui.java
 *
 * Created on 19-mar-2011, 9.20.57
 */
// versione stabile prima di aver deciso di mettere di "migliorare" le ombre
// TODO insiziare a pensare come realizzare gli effetti con timing frameWork (leggere il pdf su dropBox)

package presentation.proportional;

import control.CBacheca;
import customGuiControl.ImagePanel;
import customGuiControl.Listner.buttonRollOverListner;
import customGuiControl.Listner.wizardRollOverListner;
import customGuiControl.RoundedPanel2;
import customGuiControl.TextPane;
import customGuiControl.roundButton;
import customGuiControl.roundedPanel;
import customGuiControl.textPanel;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.Border;
import org.jdesktop.swingx.StackLayout;

/**
 *
 * @author emilio
 */
public class gui extends javax.swing.JFrame{
    
    private static gui istance=null;
    
    //maniglie dei pulsati menu sinistra
    private roundButton contattaButton;
    private roundButton inviaFotoButton;
    private roundButton gestisciRubricaButton;
    private roundButton gestisciFotoButton;
    private JPanel bacheca;
    private RoundedPanel2 panelButtonContainer;
    private RoundedPanel2 shadowedEsci;
    private RoundedPanel2 panelShadowTitolo;
    private RoundedPanel2 menuSotto;
    private JPanel panelBachecaContainer;
    private JPanel cercaBacheca;
    private JPanel modificaProfilo;
    private javax.swing.JPanel panelBacheca;
    private javax.swing.JPanel panelEsci;
    private javax.swing.JPanel panelMenuSinistra;
    private javax.swing.JPanel panelMenuSotto;
    private javax.swing.JPanel panelTitolo;
    private JPanel absolute;
    private TextPane infoTextPane;
    private JPanel firstShadowPanel;
    public static String _gestiscirubricaString="gestisciRubrica";
    public static String _gestisciFotoString="gestisciFoto";
    public static String _contattaPersonaString="contattaPersona";
    public static String _inviaFotoString="inviaFoto";
    public static String _tornaBachecaString="tornaBacheca";
    public static String _vaiBachecaContatto="vaiBachecaContatto";
    public static String _componiMessaggio="componiMessaggio";
    public static String __visualizzaMessaggio="visualizzaMessaggio";
    public static String __scriviMessaggio="scriviMessaggio";
    private ImagePanel bachecaSfondo;
    
    public static gui getIstance(){
        
        if(istance==null) istance= new gui();
        return istance;
        
    }
    private textPanel titoloText;
    
    /** Creates new form gui */
    private gui() {
        initComponents();
        this.getContentPane().setBackground(new Color(152, 72, 7));
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(0,0,screenSize.width, screenSize.height);

        this.showRoundedPanel();
        
    }
    public void showRoundedPanel()
    {
        //bordi esterni in percentuale
        float rightBorder = 0f;
        float leftBorder = 3f;
        float topBorder = 4f;
        float internalLeftBorder = 0f;
        float internalRightBorder = 0f;
        float internalUpperBottomBorder = 0f;
        
        showEsciButton(topBorder,internalRightBorder, internalUpperBottomBorder, leftBorder);
        showTitolo(topBorder, rightBorder, internalUpperBottomBorder, internalLeftBorder);
        showMenuSinistra(0.5f,internalRightBorder,1.1f,leftBorder);
        showBacheca(0.5f, rightBorder, 0f, internalLeftBorder);
        showMenuSotto(0f, rightBorder, 11f, internalLeftBorder);
    }
    
    public RoundedPanel2 getEsciButton(){
        return this.shadowedEsci;
    }

    public void showEsciButton(float topBorder, float internalRightBorder, float internalUpperBottomBorder, float leftBorder) {
        this.panelEsci.setLayout(new relativeMarginLayout(topBorder,internalRightBorder, internalUpperBottomBorder, leftBorder));
        /*this.shadowedEsci=new roundButton(20,new Color(255,255,255),
                                                    new Color(229,229,229),
                                                    2f, Color.BLACK,
                                                    2532f,100f,Color.BLACK,0.8f,
                                                    "pulsanteEsci",null);*/
        this.shadowedEsci=new RoundedPanel2();
        this.shadowedEsci.setLayout(new relativeMarginLayout(10f, 12f, 10f, 12f));
        this.shadowedEsci.add(new ImagePanel("src/images/esci.png"));

        //this.shadowedEsci.setCursor(new Cursor(Cursor.HAND_CURSOR));
        buttonRollOverListner roll=new buttonRollOverListner(new Color(152, 72, 7),
                                                             Color.BLACK,
                                                             3f, "src/images/esci_pressed.png", this, "Seleziona per uscire");
        roll.setFrameParent(this);
        this.shadowedEsci.addMouseListener(roll);

        
        JPanel stackButtonEsci= new JPanel();
        stackButtonEsci.setOpaque(false);
        stackButtonEsci.setLayout(new StackLayout());
        stackButtonEsci.add(shadowedEsci,StackLayout.TOP);
        this.panelEsci.add(stackButtonEsci);
    }

    public void showTitolo(float topBorder, float rightBorder, float internalUpperBottomBorder, float internalLeftBorder) {
        this.panelTitolo.setLayout(new relativeMarginLayout(topBorder, rightBorder, internalUpperBottomBorder, internalLeftBorder));
        /*this.panelShadowTitolo=new roundedPanel(20, new Color(255,255,255),
                                                            new Color(229,229,229),
                                                            2f, Color.BLACK,
                                                            10902.857f,100f,Color.BLACK,
                                                            0.8f,
                                                            "pannelloTitolo");*/

        this.panelShadowTitolo=new RoundedPanel2();
        
        JPanel stackTitolo=new JPanel();
        stackTitolo.setOpaque(false);
        stackTitolo.setLayout(new StackLayout());
        stackTitolo.add(this.panelShadowTitolo,StackLayout.TOP);
        this.panelTitolo.add(stackTitolo);

        //definisco la struttura interna al titolo
        this.panelShadowTitolo.setLayout(new GridBagLayout());
        JPanel panelHome= new JPanel();
        panelHome.setOpaque(false);
        JPanel Titolo=new JPanel();
        Titolo.setOpaque(false);
        //Titolo.setBackground(Color.BLUE);
        JPanel Wizard=new JPanel();
        //Wizard.setBackground(Color.CYAN);
        Wizard.setOpaque(false);
        JPanel User=new JPanel();
        User.setOpaque(false);
        //User.setBackground(Color.YELLOW);

        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx=0;
        gridBagConstraints.gridy=0;
        gridBagConstraints.weightx=0.2;
        gridBagConstraints.weighty=1.0;
        gridBagConstraints.fill=GridBagConstraints.BOTH;
        this.panelShadowTitolo.add(panelHome,gridBagConstraints);
        panelHome.setLayout(new GridBagLayout());
        JPanel panelImgHome = new JPanel();
        panelImgHome.setOpaque(false);
        GridBagConstraints gridBagConstraintsHome = new GridBagConstraints();
        gridBagConstraintsHome.gridx=0;
        gridBagConstraintsHome.gridy=0;
        gridBagConstraintsHome.weightx=0.2;
        gridBagConstraintsHome.weighty=1.0;
        gridBagConstraintsHome.fill=gridBagConstraintsHome.BOTH;
        panelHome.add(panelImgHome,gridBagConstraintsHome);
        panelImgHome.setLayout(new offsetLayout(15f, 50f, 0.9f, this.absolute));
        ImagePanel panelHomeButtonImage= new ImagePanel("src/images/home.png");
        panelHomeButtonImage.setCursor(new Cursor(Cursor.HAND_CURSOR));
        wizardRollOverListner panelHomeRoll= new wizardRollOverListner("src/images/home.png", "src/images/home_over.png", "src/images/home_pressed.png", this, "Seleziona per tornare alla tua Bacheca");
        panelHomeButtonImage.setName(this._tornaBachecaString);
        panelHomeButtonImage.addMouseListener(panelHomeRoll);
        panelImgHome.add(panelHomeButtonImage);
        panelHomeButtonImage.setParent(this.panelShadowTitolo);
        JPanel panelTextHome = new JPanel(new relativeMarginLayout(25f,25f,25f,15f));
        panelTextHome.setOpaque(false);
        gridBagConstraintsHome.gridx=1;
        gridBagConstraintsHome.gridy=0;
        gridBagConstraintsHome.weightx=0.8;
        gridBagConstraintsHome.weighty=1.0;
        gridBagConstraintsHome.fill=gridBagConstraintsHome.BOTH;
        panelHome.add(panelTextHome,gridBagConstraintsHome);
        ImagePanel panelHomeTestImage = new ImagePanel("src/images/home_text.png");
        panelTextHome.add(panelHomeTestImage);

        gridBagConstraints.gridx=1;
        gridBagConstraints.gridy=0;
        gridBagConstraints.weightx=0.4;
        gridBagConstraints.weighty=1.0;
        gridBagConstraints.fill=GridBagConstraints.BOTH;
        this.titoloText = new textPanel("La tua Bacheca");
        titoloText.setOpaque(false);
        Titolo.setLayout(new relativeMarginLayout(0f, 0f, 0f, 0f));
        Titolo.add(titoloText);
        this.panelShadowTitolo.add(Titolo,gridBagConstraints);

        //piulsante Del Wizard
        gridBagConstraints.gridx=2;
        gridBagConstraints.gridy=0;
        gridBagConstraints.weightx=0.07;
        gridBagConstraints.weighty=1.0;
        gridBagConstraints.fill=GridBagConstraints.BOTH;
        this.panelShadowTitolo.add(Wizard,gridBagConstraints);
        Wizard.setLayout(new relativeMarginLayout(14f, 18f, 12f, 18f));
        ImagePanel wizardButtonImage= new ImagePanel("src/images/nonnina.png");
        wizardButtonImage.setCursor(new Cursor(Cursor.HAND_CURSOR));
        wizardRollOverListner wizardRoll= new wizardRollOverListner("src/images/nonnina.png", "src/images/nonnina_over.png", "src/images/nonnina_pressed.png", this, "Se vuoi un maggiore aiuto clicca qui");
        wizardButtonImage.addMouseListener(wizardRoll);
        Wizard.add(wizardButtonImage);
        wizardButtonImage.setParent(this.panelShadowTitolo);
        

        gridBagConstraints.gridx=3;
        gridBagConstraints.gridy=0;
        gridBagConstraints.weightx=0.13;
        gridBagConstraints.weighty=1.0;
        gridBagConstraints.fill=GridBagConstraints.BOTH;
        this.panelShadowTitolo.add(User,gridBagConstraints);

        // uso l'ofesset layout per stabilire la posiszione dell'immagine
        // in perncentuale rispetto al suo contenutore
        User.setLayout(new offsetLayout(0f, -10f,absolute));
        ImagePanel ginevra= new ImagePanel("src/images/Ginevra.png");
        
        //VECCHIO AVATAR
        //ImagePanel ginevra= new ImagePanel("src/images/"+ CBacheca.getIstance().getCurrUser().getAvatar());
        User.add(ginevra);
        
        //wizardButtonImage.getParent().getParent().getParent().getParent().getParent().setCursor(new Cursor(Cursor.HAND_CURSOR));
        //System.out.println(wizardButtonImage.getParent().getParent().getParent().getParent().getParent().getClass());
    }
    
    public void showMenuSinistra(float topBorder, float rightBorder, float bottomBorder, float leftBorder) {
        /*this.panelButtonContainer= new roundedPanel(20, new Color(255,255,255),
                                                            new Color(229,229,229),
                                                            2f, Color.BLACK,
                                                            13883.8f,100f,Color.BLACK,
                                                            0.8f,
                                                            "pannello di Sinistra");*/
        this.panelButtonContainer=new RoundedPanel2();
        
        this.panelMenuSinistra.setLayout(new relativeMarginLayout(topBorder,rightBorder,bottomBorder,leftBorder));
        JPanel stackMenuSinistra= new JPanel();
        stackMenuSinistra.setOpaque(false);
        stackMenuSinistra.setLayout(new StackLayout());
        stackMenuSinistra.add(this.panelButtonContainer,StackLayout.TOP);
        this.panelMenuSinistra.add(stackMenuSinistra);
        
        this.fillMenuSinistra();
    }
    
    public void fillMenuSinistra()
    {
        float rightMargin=6f;
        float leftMargin=6f;
        this.panelButtonContainer.setLayout(new GridBagLayout());
        
        //=== dentro ad ogni metodo//
        //===== istanzio i pannelli di base che rappresentano i bottoni e la console====//
        //=== definisco la struttura del gridBagLayout per ogni componente
        //=== ogni pulsante sarà necessariamente composta da un pannello che sottostà
        //=== alle regole del grdBagLayoyt dichiarato precedentemente
        //=== questo pannello userà un relativeMarginLayout Per la gestione del contenuto
        //=== interno che sarà rappresentato da un ulteriore pannello con stackLayout
        //=== che conterrà a sua volta 2 pannelli uno per la creazione dell'ombra e uno che contiene
        //=== il bottone vero e proprio
        
        showContattaButton(25f, rightMargin, 5f, leftMargin);
        showInviaFotoButton(20f, rightMargin, 10f, leftMargin);
        showGestisciRubricaButton(15f, rightMargin, 15f, leftMargin);
        showGestisciFotoButton(10f, rightMargin, 20f, leftMargin);
        showInfoConsolePanel(5f, rightMargin, 15f, leftMargin);
    }
    
    private void showBacheca(float topBorder, float rightBorder, float bottomBorder, float leftBorder) {
        this.panelBacheca.setLayout(new relativeMarginLayout(topBorder,rightBorder,bottomBorder,leftBorder));
        
        this.panelBachecaContainer=new JPanel();
        this.panelBachecaContainer.setOpaque(false);
        this.panelBachecaContainer.setLayout(new relativeMarginLayout(1f, 0f, 0f, 0.6f));
        
        this.bacheca=new JPanel(new StackLayout());
        this.bacheca.setOpaque(false);
        this.bachecaSfondo=new ImagePanel("src/images/bacheca.png");
        
        this.bacheca.add( this.bachecaSfondo, StackLayout.TOP);
        
        //this.bachecaSfondo.setBounds(0, 0, this.panelBacheca.getWidth(), this.panelBacheca.getHeight());
        
        //JOptionPane.showMessageDialog(null, this.panelBacheca.getWidth());
        
        //JOptionPane.showMessageDialog(null, "Partito. Con questo barbatrucco si vede bene il JLayeredPane");
        //System.out.println(this.panelBacheca.getWidth());
        this.bachecaSfondo.setBounds(0, 0, this.panelBacheca.getWidth(), this.panelBacheca.getHeight());
        
        
        this.panelBachecaContainer.add(this.bacheca);
        
        
        JPanel stackBacheca=new JPanel();
        stackBacheca.setOpaque(false);
        stackBacheca.setLayout(new StackLayout());
        stackBacheca.add(this.panelBachecaContainer,StackLayout.TOP);
        this.panelBacheca.add(stackBacheca);
        
        
    }

    
    private void showMenuSotto(float topBorder, float rightBorder, float bottomBorder, float leftBorder) {
        this.panelMenuSotto.setLayout(new relativeMarginLayout(topBorder,rightBorder,bottomBorder,leftBorder));
        
        /*this.menuSotto= new roundedPanel(20, new Color(255,255,255),
                                                            new Color(229,229,229),
                                                            2f, Color.BLACK,
                                                            12114.286f,100f,Color.BLACK,
                                                            0.8f,
                                                            "menuSotto");*/
        this.menuSotto=new RoundedPanel2();
        JPanel stackMenuSotto= new JPanel();
        stackMenuSotto.setOpaque(false);
        stackMenuSotto.setLayout(new StackLayout());

        stackMenuSotto.add(menuSotto,StackLayout.TOP);
        //this.panelMenuSinistra.add(panelButtonContainer);
        this.panelMenuSotto.add(stackMenuSotto);

        //=== iniziao la creazione del menu sotto, il problema è che questa struttura cambia
        //=== dinamicamente in maniera forte a seconda delle sezioni in cui ci troviamo
       // this.fillMenuSotto();
        PBacheca.getInstance().refreshMenuSotto(this);
        this.cleanRebuildMenu(PBacheca.getInstance().getMenuSotto());
    }

    public void fillMenuSotto() {

        this.menuSotto.setLayout(new GridBagLayout());
        
        
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints = new GridBagConstraints();

        gridBagConstraints.gridx=0;
        gridBagConstraints.gridy=0;
        gridBagConstraints.weightx=0.99;
        gridBagConstraints.weighty=1.0;
        gridBagConstraints.fill=GridBagConstraints.BOTH;
        this.cercaBacheca= new JPanel();
        //cercaBacheca.setBackground(Color.red);
        cercaBacheca.setOpaque(false);
        Border border=BorderFactory.createMatteBorder(0,0,0,2,new Color(128,128,128));
        this.menuSotto.add(cercaBacheca, gridBagConstraints);
        cercaBacheca.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel cercaIcon=new ImagePanel("src/images/cercaBacheca.png");
        wizardRollOverListner cercaRoll=new wizardRollOverListner(
                                    "src/images/cercaBacheca.png",
                                    "src/images/cercaBachecaOver.png",
                                    "src/images/cercaBachecaPressed.png", this, "Seleziona per cercare nella bacheca");
        cercaRoll.setFrameParent(this);
        cercaIcon.addMouseListener(cercaRoll);
        cercaIcon.setParent(this.menuSotto);
        cercaBacheca.add(cercaIcon);


        gridBagConstraints.gridx=1;
        gridBagConstraints.gridy=0;
        gridBagConstraints.weightx=0.01;
        gridBagConstraints.weighty=1.0;
        gridBagConstraints.fill=GridBagConstraints.BOTH;
        
        JPanel borderPanelContainer=new JPanel(new relativeMarginLayout(11.75f, 30f, 11.75f, 30f));
        //borderPanelContainer.setBackground(Color.red);
        borderPanelContainer.setOpaque(false);
        this.menuSotto.add(borderPanelContainer,gridBagConstraints);
        JPanel borderPanel= new JPanel();
        borderPanel.setBackground(new Color(166,166,166));
        borderPanelContainer.add(borderPanel);

        gridBagConstraints.gridx=2;
        gridBagConstraints.gridy=0;
        gridBagConstraints.weightx=0.99;
        gridBagConstraints.weighty=1.0;
        gridBagConstraints.fill=GridBagConstraints.BOTH;
        this.modificaProfilo= new JPanel();
        //modificaProfilo.setBackground(Color.yellow);
        modificaProfilo.setOpaque(false);
        this.menuSotto.add(modificaProfilo, gridBagConstraints);
        modificaProfilo.setLayout(new relativeMarginLayout(10f, 5f, 5f, 5f));
        ImagePanel modificaIcon= new ImagePanel("src/images/modificaProfilo.png");
        wizardRollOverListner modificaRoll=new wizardRollOverListner(
                                                    "src/images/modificaProfilo.png",
                                                    "src/images/modificaProfiloOver.png",
                                                    "src/images/modificaProfiloPressed.png", this, "Seleziona per modificare il tuo profilo");
        modificaRoll.setFrameParent(this);
        modificaIcon.addMouseListener(modificaRoll);
        modificaIcon.setParent(this.menuSotto);
        modificaProfilo.add(modificaIcon);
    }
    public void cleanRebuildMenu(JPanel panel){
        ((JPanel)this.panelMenuSotto.getComponent(0)).remove(0);
        this.menuSotto.setVisible(false);
        ((JPanel)this.panelMenuSotto.getComponent(0)).add(panel);
        //this.panelMenuSotto.add(panel);
        this.menuSotto.setVisible(true);
        
    }
    public roundedPanel getContattaButton() {
        return contattaButton;
    }

    public void setContattaButton(roundButton contattaButton) {
        this.contattaButton = contattaButton;
    }
    
    public void showContattaButton(float topMargin, float rightMargin, float bottomMargin, float leftMargin){
        JPanel contattaRelativePanel= new JPanel(new relativeMarginLayout(topMargin, rightMargin, bottomMargin, leftMargin));
        contattaRelativePanel.setOpaque(false);
        
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx=0;
        gridBagConstraints.gridy=0;
        gridBagConstraints.weightx=1.0;
        gridBagConstraints.weighty=1.0;
        gridBagConstraints.fill=GridBagConstraints.BOTH;
        this.contattaButton= new roundButton(20, new Color(255,239,209),
                                                            new Color(209,195,159),
                                                            1f, Color.BLACK,
                                                            1739.1f,100f,Color.BLACK,
                                                            0.7f,
                                                            "contattaButton","src/images/contatta.png");
        this.contattaButton.setRoot(this);
        JPanel contattaStackPanel= new JPanel(new StackLayout());
        contattaStackPanel.setOpaque(false);
        contattaStackPanel.add(this.contattaButton,StackLayout.TOP);
        contattaRelativePanel.add(contattaStackPanel);
        this.panelButtonContainer.add(contattaRelativePanel,gridBagConstraints);
        this.contattaButton.setLayout(new relativeMarginLayout(5f, 5f, 12f, 5f));
        this.contattaButton.add(new ImagePanel("src/images/contatta_persona.png"));
        //this.setCursor(new Cursor(Cursor.HAND_CURSOR));
        buttonRollOverListner roll=new buttonRollOverListner(Color.WHITE,Color.BLACK,2f, "src/images/contatta_persona_pressed.png", this,  "Seleziona per contattare una persona");
        roll.setFrameParent(this);

        this.contattaButton.setName(this._contattaPersonaString);
        this.contattaButton.addMouseListener(roll);
    }

    public roundedPanel getGestisciFotoButton() {
        return gestisciFotoButton;
    }

    public void setGestisciFotoButton(roundButton gestisciFotoButton) {
        this.gestisciFotoButton = gestisciFotoButton;
    }
    
    public void showGestisciFotoButton(float topMargin, float rightMargin, float bottomMargin, float leftMargin) {
        JPanel gestisciFotoPanel = new JPanel(new relativeMarginLayout(topMargin, rightMargin, bottomMargin, leftMargin));
        gestisciFotoPanel.setOpaque(false);
        
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx=0;
        gridBagConstraints.gridy=3;
        gridBagConstraints.weightx=1.0;
        gridBagConstraints.weighty=1.0;
        gridBagConstraints.fill=GridBagConstraints.BOTH;
        this.gestisciFotoButton= new roundButton(20, new Color(126,196,216),
                                                            new Color(72,165,191),
                                                            new Float(1), Color.BLACK,
                                                            1720.4f,100f,Color.BLACK,
                                                            0.7f,
                                                            "gestisciFoto",null);
        JPanel gestisciFotoStackPanel= new JPanel(new StackLayout());
        gestisciFotoStackPanel.setOpaque(false);
        gestisciFotoStackPanel.add(this.gestisciFotoButton,StackLayout.TOP);
        gestisciFotoPanel.add(gestisciFotoStackPanel);
        this.panelButtonContainer.add(gestisciFotoPanel,gridBagConstraints);
        this.gestisciFotoButton.setLayout(new relativeMarginLayout(5f, 5f, 12f, 5f));
        this.gestisciFotoButton.add(new ImagePanel("src/images/gestisci_foto.png"));
        //this.gestisciFotoButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
        buttonRollOverListner roll=new buttonRollOverListner(Color.WHITE,Color.BLACK,2f, "src/images/gestisci_foto_pressed.png", this, "Seleziona per gestire le tue foto");
        roll.setFrameParent(this);
        
        this.gestisciFotoButton.setName(this._gestisciFotoString);
        this.gestisciFotoButton.addMouseListener(roll);
    }

    public roundedPanel getGestisciRubricaButton() {
        return gestisciRubricaButton;
    }

    public void setGestisciRubricaButton(roundButton gestisciRubricaButton) {
        this.gestisciRubricaButton = gestisciRubricaButton;
    }
    
    public void showGestisciRubricaButton(float topMargin, float rightMargin, float bottomMargin, float leftMargin) {
        JPanel gestisciRubricaPanel= new JPanel(new relativeMarginLayout(topMargin, rightMargin, bottomMargin, leftMargin));
        gestisciRubricaPanel.setOpaque(false);
        
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx=0;
        gridBagConstraints.gridy=2;
        gridBagConstraints.weightx=1.0;
        gridBagConstraints.weighty=1.0;
        gridBagConstraints.fill=GridBagConstraints.BOTH;
        this.gestisciRubricaButton= new roundButton(20, new Color(255,164,67),
                                                            new Color(255,116,0),
                                                            new Float(1), Color.BLACK,
                                                            1739.1f,100f,Color.BLACK,
                                                            0.7f,
                                                            "gestisciRubrica","src/images/rubricaSelect.png");
        this.gestisciRubricaButton.setRoot(this);
        JPanel gestisciRubricaStackPanel= new JPanel(new StackLayout());
        gestisciRubricaStackPanel.setOpaque(false);
        gestisciRubricaStackPanel.add(this.gestisciRubricaButton,StackLayout.TOP);
        gestisciRubricaPanel.add(gestisciRubricaStackPanel);
        this.panelButtonContainer.add(gestisciRubricaPanel,gridBagConstraints);
        this.gestisciRubricaButton.setLayout(new relativeMarginLayout(5f, 5f, 12f, 5f));
        this.gestisciRubricaButton.add(new ImagePanel("src/images/gestisci_rubrica.png"));
        buttonRollOverListner roll=new buttonRollOverListner(Color.WHITE,Color.BLACK,2f, "src/images/gestisci_rubrica_pressed.png", this, "Seleziona per gestire la tua rubrica");
        roll.setFrameParent(this);
        this.gestisciRubricaButton.setName(this._gestiscirubricaString);
        this.gestisciRubricaButton.addMouseListener(roll);
    }
    
    public void showInfoConsolePanel(float topMargin, float rightMargin, float bottomMargin, float leftMargin) {
        JPanel infoConsolePanel= new JPanel(new relativeMarginLayout(topMargin, rightMargin, bottomMargin, leftMargin));
        infoConsolePanel.setOpaque(false);
        
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx=0;
        gridBagConstraints.gridy=4;
        gridBagConstraints.weightx=1.0;
        gridBagConstraints.weighty=1.0;
        gridBagConstraints.fill=GridBagConstraints.BOTH;
        JPanel infoConsole=new JPanel();
        infoConsole.setBackground(new Color(198,217,241));
        Border border=BorderFactory.createMatteBorder(2,2,2,2,new Color(55,96,146));
        infoConsole.setBorder(border);
        infoConsolePanel.add(infoConsole);
        infoConsole.setLayout(new StackLayout());

        this.infoTextPane= new TextPane("Posiziona il curosore su un elemento", false, false);
        infoConsole.add(this.infoTextPane, StackLayout.TOP);
            
        JPanel panelToolTip = new JPanel(new GridBagLayout());
        panelToolTip.setOpaque(false);

            GridBagConstraints gridBagConstraintsConsole = new GridBagConstraints();
            gridBagConstraintsConsole.gridx=0;
            gridBagConstraintsConsole.gridy=0;
            gridBagConstraintsConsole.weightx=0.2;
            gridBagConstraintsConsole.weighty=0.4;
            gridBagConstraintsConsole.fill=GridBagConstraints.BOTH;
            JPanel p1= new JPanel(new relativeMarginLayout(5f, 5f, 5f, 5f));
            p1.setOpaque(false);

            ImagePanel toolTip = new ImagePanel("src/images/infoTooltip.png");
            p1.add(toolTip);
            
            panelToolTip.add(p1, gridBagConstraintsConsole);

            gridBagConstraintsConsole = new GridBagConstraints();
            gridBagConstraintsConsole.gridx=1;
            gridBagConstraintsConsole.gridy=0;
            gridBagConstraintsConsole.weightx=0.8;
            gridBagConstraintsConsole.weighty=0.4;
            gridBagConstraintsConsole.fill=GridBagConstraints.BOTH;
            JPanel p2= new JPanel();
            p2.setOpaque(false);
            panelToolTip.add(p2, gridBagConstraintsConsole);

            gridBagConstraintsConsole = new GridBagConstraints();
            gridBagConstraintsConsole.gridx=0;
            gridBagConstraintsConsole.gridy=1;
            gridBagConstraintsConsole.weightx=0.2;
            gridBagConstraintsConsole.weighty=0.6;
            gridBagConstraintsConsole.fill=GridBagConstraints.BOTH;
            JPanel p3= new JPanel();
            p3.setOpaque(false);
            panelToolTip.add(p3, gridBagConstraintsConsole);

            gridBagConstraintsConsole = new GridBagConstraints();
            gridBagConstraintsConsole.gridx=1;
            gridBagConstraintsConsole.gridy=1;
            gridBagConstraintsConsole.weightx=0.8;
            gridBagConstraintsConsole.weighty=0.6;
            gridBagConstraintsConsole.fill=GridBagConstraints.BOTH;
            JPanel p4= new JPanel();
            p4.setOpaque(false);
            panelToolTip.add(p4, gridBagConstraintsConsole);

        infoConsole.add(panelToolTip, StackLayout.TOP);

        this.panelButtonContainer.add(infoConsolePanel,gridBagConstraints);
    }

    public roundedPanel getInviaFotoButton() {
        return inviaFotoButton;
    }

    public void setInviaFotoButton(roundButton inviaFotoButton) {
        this.inviaFotoButton = inviaFotoButton;
    }
    
    public void showInviaFotoButton(float topMargin, float rightMargin, float bottomMargin, float leftMargin) {
        
        JPanel inviaFotorelativePanel= new JPanel(new relativeMarginLayout(topMargin, rightMargin, bottomMargin, leftMargin));
        inviaFotorelativePanel.setOpaque(false);
        
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx=0;
        gridBagConstraints.gridy=1;
        gridBagConstraints.weightx=1.0;
        gridBagConstraints.weighty=1.0;
        gridBagConstraints.fill=GridBagConstraints.BOTH;
        this.inviaFotoButton= new roundButton(20, new Color(215,228,189),
                                                            new Color(119,147,60),
                                                            new Float(1), Color.BLACK,
                                                            1720.4f,100f,Color.BLACK,
                                                            0.7f,
                                                            "inviaFoto",null);
        JPanel inviaFotoStackPanel= new JPanel(new StackLayout());
        inviaFotoStackPanel.setOpaque(false);
        inviaFotoStackPanel.add(this.inviaFotoButton,StackLayout.TOP);
        inviaFotorelativePanel.add(inviaFotoStackPanel);
        this.panelButtonContainer.add(inviaFotorelativePanel,gridBagConstraints);
        this.inviaFotoButton.setLayout(new relativeMarginLayout(5f, 5f, 12f, 5f));
        this.inviaFotoButton.add(new ImagePanel("src/images/invia_foto.png"));
        //this.inviaFotoButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
        buttonRollOverListner roll=new buttonRollOverListner(Color.WHITE,Color.BLACK,2f, "src/images/invia_foto_pressed.png", this,  "Seleziona per inviare una foto");
        roll.setFrameParent(this);
        this.inviaFotoButton.addMouseListener(roll);
    }

    public RoundedPanel2 getPanelButtonContainer() {
        return panelButtonContainer;
    }

    public void setPanelButtonContainer(RoundedPanel2 panelButtonContainer) {
        this.panelButtonContainer = panelButtonContainer;
    }

    public RoundedPanel2 getShadowedEsci() {
        return shadowedEsci;
    }

    public void setShadowedEsci(RoundedPanel2 shadowedEsci) {
        this.shadowedEsci = shadowedEsci;
    }

    public RoundedPanel2 getPanelShadowTitolo() {
        return panelShadowTitolo;
    }

    public void setPanelShadowTitolo(RoundedPanel2 panelShadowTitolo) {
        this.panelShadowTitolo = panelShadowTitolo;
    }

    public JPanel getCercaBacheca() {
        return cercaBacheca;
    }

    public void setCercaBacheca(JPanel cercaBacheca) {
        this.cercaBacheca = cercaBacheca;
    }

    public JPanel getModificaProfilo() {
        return modificaProfilo;
    }

    public void setModificaProfilo(JPanel modificaProfilo) {
        this.modificaProfilo = modificaProfilo;
    }

    public TextPane getInfoTextPane() {
        return infoTextPane;
    }

    public JPanel getFirstShadowPanel() {
        return firstShadowPanel;
    }

    public void setFirstShadowPanel(JPanel firstShadowPanel) {
        this.firstShadowPanel = firstShadowPanel;
    }
    

    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        panelMenuSinistra = new javax.swing.JPanel();
        panelBacheca = new javax.swing.JPanel();
        panelMenuSotto = new javax.swing.JPanel();
        panelEsci = new javax.swing.JPanel();
        panelTitolo = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(152, 72, 7));
        setForeground(new java.awt.Color(71, 71, 71));
        setMinimumSize(new java.awt.Dimension(1024, 600));

        // il content pane sarà di tipo stackLayout
        // in modo tale da poter realizzare un layout a Livelli
        this.getContentPane().setLayout(new StackLayout());
        this.firstShadowPanel=new JPanel(null);
        this.firstShadowPanel.setOpaque(false);
        this.getContentPane().add(this.firstShadowPanel, StackLayout.TOP);
        JPanel principalPanel=new JPanel();
        
        principalPanel.setOpaque(false);
        this.getContentPane().add(principalPanel,StackLayout.TOP);
        principalPanel.setLayout(new java.awt.GridBagLayout());

        // aggiungo un nuovo pannello con posizionamento assoluto
        // nello stack
        this.absolute=new JPanel(null);
        absolute.setOpaque(false);
        this.getContentPane().add(absolute,StackLayout.TOP);

        panelMenuSinistra.setBackground(new java.awt.Color(171, 187, 55));
        panelMenuSinistra.setOpaque(false);
        panelMenuSinistra.setLayout(null);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.17;
        gridBagConstraints.weighty = 0.9;
        principalPanel.add(panelMenuSinistra, gridBagConstraints);

        panelBacheca.setBackground(new java.awt.Color(4, 255, 217));
        panelBacheca.setOpaque(false);
        panelBacheca.setLayout(null);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.83;
        gridBagConstraints.weighty = 0.78;
        principalPanel.add(panelBacheca, gridBagConstraints);

        panelMenuSotto.setBackground(new java.awt.Color(129, 238, 0));
        panelMenuSotto.setOpaque(false);
        panelMenuSotto.setLayout(null);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.83;
        gridBagConstraints.weighty = 0.12;
        principalPanel.add(panelMenuSotto, gridBagConstraints);

        panelEsci.setBackground(new java.awt.Color(204, 55, 55));
        panelEsci.setOpaque(false);
        panelEsci.setLayout(null);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.17;
        gridBagConstraints.weighty = 0.1;
        principalPanel.add(panelEsci, gridBagConstraints);

        panelTitolo.setBackground(new java.awt.Color(224, 186, 2));
        panelTitolo.setOpaque(false);
        panelTitolo.setLayout(null);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.83;
        gridBagConstraints.weighty = 0.1;
        principalPanel.add(panelTitolo, gridBagConstraints);

        pack();
        
    }// </editor-fold>//GEN-END:initComponents
    /**
    * @param args the command line arguments
    */
   

    public JPanel getAbsolutePane() {
        return this.absolute;
    }
    
    public void buttonClicked(String name) {
       
      
       
      String imgUrl="";
      JPanel currentPanel=new JPanel();
      currentPanel.setOpaque(false);
       
       
       if(name==this._gestiscirubricaString){
           imgUrl="src/images/pannello_arancio.png";
           currentPanel=PGestioneRubrica.getInstance().getPanel();
           this.titoloText.setTextOnPanel("Gestisci Rubrica");
           cleanRebuildMenu(PGestioneRubrica.getInstance().getMenuSotto(this));
       }
       else if(name==this._contattaPersonaString){
           imgUrl="src/images/pannello_grigio.png";
           currentPanel=PContattaPersona.getInstance().getPanel();
           this.titoloText.setTextOnPanel("Contatta Persona");
           cleanRebuildMenu(PContattaPersona.getInstance().getMenuSotto(this));
       }
       else if(name==this._vaiBachecaContatto){
           imgUrl="src/images/sfondo_altra_bacheca.png";
           currentPanel=PBacheca.getInstance().getPanel();
           this.titoloText.setTextOnPanel("Bacheca di " + PGestioneRubrica.getInstance().getClickedUser().getNickname());
           cleanRebuildMenu(PBacheca.getInstance().getMenuSottoContatto(this));
       }
       else if(name==this._gestisciFotoString){ 
           imgUrl="src/images/pannello_blu.png";
           this.titoloText.setTextOnPanel("Gestisci Foto");
       }
       else if(name==this._inviaFotoString){
           imgUrl="src/images/pannello_blu.png";
           this.titoloText.setTextOnPanel("Invia Foto");
       }
        else if(name==this._tornaBachecaString){
           PBacheca.getInstance().refreshPanel(null);
           imgUrl="src/images/bacheca.png";
           currentPanel=PBacheca.getInstance().getPanel();
           this.titoloText.setTextOnPanel("La tua Bacheca");
           cleanRebuildMenu(PBacheca.getInstance().getMenuSotto());
       }
        else if(name==this.__scriviMessaggio){
           imgUrl="src/images/componi_messaggio.png";
           currentPanel=PComponiMessaggio.getInstance().getPanel();
           this.titoloText.setTextOnPanel("Composizione Messaggio");
           cleanRebuildMenu(PComponiMessaggio.getInstance().getMenuSotto(this));
          
       }
        else if(name==this._componiMessaggio){
           imgUrl="src/images/componi_messaggio.png";
           currentPanel=PComponiMessaggio.getInstance().getPanel();
           this.titoloText.setTextOnPanel("Composizione Messaggio");
           cleanRebuildMenu(PComponiMessaggio.getInstance().getMenuSotto(this));
         
       }
        else if(name==this.__visualizzaMessaggio){
            imgUrl="src/images/componi_messaggio.png";
            currentPanel=PVisualizzaMessaggio.getInstance().getPanel();
            this.titoloText.setTextOnPanel("Visualizzazione Messaggio");
            cleanRebuildMenu(PVisualizzaMessaggio.getInstance().getMenuSotto(this));
            
        }
       else{}
       
       if(!imgUrl.isEmpty()){
            this.bachecaSfondo.setBounds(0, 0, this.panelBacheca.getWidth(), this.panelBacheca.getHeight());
       
            this.bacheca.removeAll();
            this.bacheca.setLayout(new StackLayout());
            this.bachecaSfondo.setPathImg(imgUrl);
            this.bacheca.add(currentPanel,StackLayout.TOP);
            this.bacheca.add(this.bachecaSfondo, StackLayout.BOTTOM);
            this.bacheca.repaint();
            this.panelBachecaContainer.repaint();
       }
    }
    
    
    
    public static String getContattaPersonaString() {
        return _contattaPersonaString;
    }

    public static void setContattaPersonaString(String _contattaPersonaString) {
        gui._contattaPersonaString = _contattaPersonaString;
    }

    public static String getGestisciFotoString() {
        return _gestisciFotoString;
    }

    public static void setGestisciFotoString(String _gestisciFotoString) {
        gui._gestisciFotoString = _gestisciFotoString;
    }

    public static String getGestiscirubricaString() {
        return _gestiscirubricaString;
    }

    public static void setGestiscirubricaString(String _gestiscirubricaString) {
        gui._gestiscirubricaString = _gestiscirubricaString;
    }

    public static String getInviaFotoString() {
        return _inviaFotoString;
    }

    public static void setInviaFotoString(String _inviaFotoString) {
        gui._inviaFotoString = _inviaFotoString;
    }

    public static String getTornaBachecaString() {
        return _tornaBachecaString;
    }

    public static void setTornaBachecaString(String _tornaBachecaString) {
        gui._tornaBachecaString = _tornaBachecaString;
    }

    public JPanel getAbsolute() {
        return absolute;
    }

    public void setAbsolute(JPanel absolute) {
        this.absolute = absolute;
    }

    public JPanel getBacheca() {
        return bacheca;
    }

    public void setBacheca(JPanel bacheca) {
        this.bacheca = bacheca;
    }

    public ImagePanel getBachecaSfondo() {
        return bachecaSfondo;
    }

    public void setBachecaSfondo(ImagePanel bachecaSfondo) {
        this.bachecaSfondo = bachecaSfondo;
    }

    public RoundedPanel2 getMenuSotto() {
        return menuSotto;
    }

    public void setMenuSotto(RoundedPanel2 menuSotto) {
        this.menuSotto = menuSotto;
    }

    public JPanel getPanelBacheca() {
        return panelBacheca;
    }

    public void setPanelBacheca(JPanel panelBacheca) {
        this.panelBacheca = panelBacheca;
    }

    public JPanel getPanelBachecaContainer() {
        return panelBachecaContainer;
    }

    public void setPanelBachecaContainer(JPanel panelBachecaContainer) {
        this.panelBachecaContainer = panelBachecaContainer;
    }

    public JPanel getPanelEsci() {
        return panelEsci;
    }

    public void setPanelEsci(JPanel panelEsci) {
        this.panelEsci = panelEsci;
    }

    public JPanel getPanelMenuSinistra() {
        return panelMenuSinistra;
    }

    public void setPanelMenuSinistra(JPanel panelMenuSinistra) {
        this.panelMenuSinistra = panelMenuSinistra;
    }

    public JPanel getPanelMenuSotto() {
        return panelMenuSotto;
    }

    public void setPanelMenuSotto(JPanel panelMenuSotto) {
        this.panelMenuSotto = panelMenuSotto;
    }

    public JPanel getPanelTitolo() {
        return panelTitolo;
    }

    public void setPanelTitolo(JPanel panelTitolo) {
        this.panelTitolo = panelTitolo;
    }
    
}
